package org.luxor.commons.zookeeper.globallock;

import org.apache.curator.framework.recipes.locks.InterProcessMutex;
import org.luxor.commons.zookeeper.lock.GlobalLockTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class LockTemplateService {
    public static int count;

    @Resource
    private GlobalLockTemplate globalLockTemplate;

    public void simple() {
        InterProcessMutex lock = null;
        try {
            lock = globalLockTemplate.lock("/locks");
            count++;
            System.out.println("[" + count + "]执行简单方法2 , 当前线程:" + Thread.currentThread().getName());
        } finally {
            globalLockTemplate.releaseLock(lock);
        }
    }

}
